package unitest.Suite.tests
{
	import com.flashshe.ds.linear.IQueue;
	import com.flashshe.ds.linear.VectorQueue;
	import flexunit.framework.Assert;
	
	
	public class TestQueue
	{		
		private var queue:IQueue;
		
		[Before]
		public function setUp():void
		{
			queue = new VectorQueue();		
			queue.enqueue("a");
			queue.enqueue("b");
		}		
		
		[Test]
		public function enqueueElements():void
		{			
			Assert.assertTrue(queue.contains("a"));
			Assert.assertTrue(queue.contains("b"));
		}
		
		[Test]
		public function dequeueElements():void
		{
			queue.dequeue();
			Assert.assertTrue(queue.contains("b"));
			Assert.assertFalse(queue.contains("a"));
			queue.dequeue();
			Assert.assertFalse(queue.contains("b"));
		}
		
		[Test]
		public function getDequeuedElement():void
		{
			Assert.assertEquals("a", queue.dequeue());
			Assert.assertEquals("b", queue.dequeue());
		}
		
		[Test]
		public function peek():void
		{
			queue.clear();
			Assert.assertNull(queue.peek());
			queue.enqueue("a");
			Assert.assertEquals("a", queue.peek());
			queue.enqueue("b");
			Assert.assertEquals("a", queue.peek());
		}
		[Test]
		public function getValue():void
		{
			queue.clear();
			Assert.assertNull(queue.getValue());
			queue.enqueue("a");
			Assert.assertEquals("a", queue.getValue());
			queue.enqueue("b");
			Assert.assertEquals("a", queue.getValue());
		}
		
		[Test]
		public function addElements():void
		{			
			queue.enqueue("c");
			queue.enqueue("d");
			Assert.assertTrue(queue.contains("c"));
			Assert.assertTrue(queue.contains("d"));
		}
		
		[Test]
		public function removeElements():void
		{
			queue.dequeue();
			Assert.assertTrue(queue.contains("b"));
			Assert.assertFalse(queue.contains("a"));
			queue.dequeue();
			Assert.assertFalse(queue.contains("b"));
		}
		
		[Test]
		public function getRemovedElement():void
		{
			Assert.assertEquals("a", queue.dequeue());
			Assert.assertEquals("b", queue.dequeue());
		}
		
		[Test]
		public function size():void
		{
			queue.clear();
			Assert.assertEquals(0, queue.size);			
			queue.enqueue("a");			
			queue.enqueue("b");
			Assert.assertEquals(2, queue.size);	
			queue.dequeue();		
			Assert.assertEquals(1, queue.size);
		}
		
		[Test]
		public function isEmpty():void
		{
			queue.clear();
			Assert.assertTrue(queue.isEmpty());				
			queue.enqueue("a");			
			Assert.assertFalse(queue.isEmpty());		
		}
		
		[Test]
		public function clear():void
		{
			Assert.assertFalse(queue.isEmpty());
			queue.enqueue("c");
			queue.clear();
			Assert.assertTrue(queue.isEmpty());						
		}
		
		[Test]
		public function contains():void
		{
			queue.clear();
			queue.enqueue("c");
			queue.enqueue("d");
			Assert.assertTrue(queue.contains("c"));		
			queue.dequeue();
			Assert.assertFalse(queue.contains("c"));		
		}
	}
}